# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import fields, models

class Channel(models.Model):
    _inherit = 'mail.channel'

    def sendmany(self, data, *args, **kwargs):
        if not isinstance(data, (list, tuple)):
            return False

        for channel in self:
            chn = (self._cr.dbname, 'mail.channel', channel.id)
            to_send = [ [chn, msg ] for msg in data ]
            self.env['bus.bus'].sendmany(to_send)

        return True

    def sendone(self, data, *args, **kwargs):
        if not isinstance(data, dict):
            return False

        for channel in self:
            self.env['bus.bus'].sendone((self._cr.dbname, 'mail.channel', channel.id), data)

        return True
